'use strict';

module.exports = app => {
  // 引入数据类型
  const { STRING, INTEGER, TEXT } = app.Sequelize;
  // 建模 创建表user自动加的s
  const UserRelation = app.model.define('UserRelation', {
    userId: {
      type: INTEGER,
      allowNull: false,
      comment: '粉丝的id',
    },
    followerId: {
      type: INTEGER,
      allowNull: false,
      comment: '被关注人的id'
    }
  });
  // 创建外键
  UserRelation.associate = () => {
    // 用户可以关注多个人
    app.model.UserRelation.belongsTo(app.model.User, {
      foreignKey: 'followerId',
    });
  };
  return UserRelation;
}